<?php


namespace app\model\article;


use app\model\config\RegionModel;
use app\model\user\UserModel;
use think\Model;
use think\model\concern\SoftDelete;

class ArticleApplyModel extends Model
{
    protected $name = 'article_apply';
    protected $autoWriteTimestamp = true;

    use SoftDelete;
    protected $defaultSoftDelete = 0;

    public function article()
    {
        return $this->hasOne(ArticleModel::class, 'id', 'article_id')->bind([
            'article_name' => 'title',
            'article_img' => 'img',
            'article_content' => 'content',
            'article_begin_time' => 'begin_time',
            'article_end_time' => 'end_time',
        ]);
    }

    public function city()
    {
        return $this->hasOne(RegionModel::class, 'id', 'city_id')->bind(['city_name' => 'name']);
    }

    public function user()
    {
        return $this->hasOne(UserModel::class, 'id', 'user_id')->bind(['username','mobile']);
    }

    public function getSignTimeAttr($value)
    {
        if (!$value) {
            return '';
        }
        return date('Y-m-d H:i:s', $value);
    }

    public function getCancelTimeAttr($value)
    {
        if (!$value) {
            return '';
        }
        return date('Y-m-d H:i:s', $value);
    }
}